/**
 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef PANDA_TOOLING_TEST_JS_VM_EVENT_TEST_H
#define PANDA_TOOLING_TEST_JS_VM_EVENT_TEST_H

#include "test_util.h"

namespace ark::tooling::test {
class JsVmEventTest : public ApiTest {
public:
    JsVmEventTest()
    {
        vmStart = [this]() {
            startCounter_++;
            return true;
        };

        vmInit = [this](PtThread thread) {
            initThread_ = thread.GetId();
            initCounter_++;
            return true;
        };

        vmDeath = [this]() {
            deathCounter_++;
            ASSERT_NE(initThread_, PtThread::NONE.GetId());
            ASSERT_EQ(startCounter_, 1U);
            ASSERT_EQ(initCounter_, 1U);
            return true;
        };
    }

    std::pair<const char *, const char *> GetEntryPoint() override
    {
        return {pandaFile_.c_str(), entryPoint_.c_str()};
    }

private:
    std::string pandaFile_ = "js/Sample.abc";
    std::string entryPoint_ = "_GLOBAL::func_main_0";
    size_t startCounter_ = 0;
    size_t initCounter_ = 0;
    size_t deathCounter_ = 0;
    uint32_t initThread_ = PtThread::NONE.GetId();
};

inline std::unique_ptr<ApiTest> GetJsVmEventTest()
{
    return std::make_unique<JsVmEventTest>();
}
}  // namespace ark::tooling::test

#endif  // PANDA_TOOLING_TEST_JS_VM_EVENT_TEST_H
